/*
 * listenhandler.h
 *
 *  Created on: 2013. 7. 19.
 *      Author: jjaehuny
 */

#ifndef LISTENHANDLER_H_
#define LISTENHANDLER_H_

#include <Dispatcher/Static.h>
#include "ChannelServer.h"

#include "Static.h"
#include "User.h"

namespace FriendsServer
{

class ListenHandler : public Dispatcher::ListenHandler<ChannelServer, Network::Packet>
{
public:
	ListenHandler() {}
	virtual ~ListenHandler() {}

	virtual void OnConnect(ChannelServer* pSession, const char* ip)
	{
		LOG(DEV, "(session_key:", pSession->GetSessionKey(), ", sock:", pSession->GetSocket(), ", ip:", ip, ")");
	}
	virtual void OnClose(ChannelServer* pSession, int nReason)
	{
		LOG(DEV, "(session_key:", pSession->GetSessionKey(), ", sock:", pSession->GetSocket(), ", errno:", nReason, " errstr:", strerror(errno), ")");
		LOG(DEV, "(channel_key:", pSession->GetChannelKey(), ", sock:", pSession->GetSocket(), ", errno:", nReason, " errstr:", strerror(errno), ")");

		auto & clsTreeVector = Static::Instance().GetTreeVector();
		std::for_each(clsTreeVector.begin(), clsTreeVector.end(), [&](MAP & map) {

			std::for_each(map.begin(), map.end(), [&](MAP::value_type & pair) {
				if ( pSession->GetChannelKey() == pair.second->GetChannelKey())
				{
					//pair.second->SetRandomTime();
				}
			} );

		} );
	}
};

} /* namespace FriendsServer */


#endif /* LISTENHANDLER_H_ */
